using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

namespace GTask
{
    /// <summary>
    /// 任务项
    /// </summary>
    public class TaskItem
    {
        /// <summary>
        /// 任务号
        /// </summary>
        public string TASK_ID = "";
        /// <summary>
        /// 进程编号
        /// </summary>
        public string PROCESS_ID = "";
        /// <summary>
        /// 任务线程
        /// </summary>
        public BackgroundWorker bgw = null;
        /// <summary>
        /// 初始化类的新实例
        /// </summary>
        /// <param name="dr">数据</param>
        public TaskItem(DataRow dr)
        {
            TASK_ID = dr["TASK_ID"].ToString();
            PROCESS_ID = dr["PROCESS_ID"].ToString();
        }
    }

    /// <summary>
    /// 任务项集合
    /// </summary>
    public class TaskItemCollection : List<TaskItem>
    {
        /// <summary>
        /// 按任务获取任务项
        /// </summary>
        /// <param name="task_id">任务编号</param>
        /// <returns>任务项</returns>
        public TaskItem this[string task_id]
        {
            get
            {
                TaskItem item = null;
                for (int i = 0; i < base.Count; i++)
                {
                    if (base[i].TASK_ID.Equals(task_id))
                    {
                        item = base[i];
                        break;
                    }
                }
                return item;
            }
        }
        /// <summary>
        /// 按任务获取任务项
        /// </summary>
        /// <param name="backgroundWorkerTask">任务</param>
        /// <returns>任务项</returns>
        public TaskItem this[BackgroundWorker backgroundWorkerTask]
        {
            get
            {
                TaskItem item = null;
                for (int i = 0; i < base.Count; i++)
                {
                    if (backgroundWorkerTask.Equals(base[i].bgw))
                    {
                        item = base[i];
                        break;
                    }
                }
                return item;
            }
        }
    }
}
